<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>MCU MANAGER</title>
	<%@ include file="/WEB-INF/jsp/common/cssjs2.jsp" %>
	
	<script type="text/javascript">
		$(function(){
			$('.easyui-validatebox').validatebox();
			$('.easyui-validatebox[required]').after("<font color='red'> *</font>");	

            if("${sip.enabled}"=="true" || "${sip.enabled}"=="yes" || "${sip.enabled}"=="enable"){
					$("#id_enabled").attr("checked",true);
                    $("#id_h_enabled").val("true");
			}
            else {
                $("#id_h_enabled").val("false");
            }

			
            $("#id_enabled").change(function(){
				var checked=this.checked;
				if(checked){
					$("#id_h_enabled").val("true");
				}else{
					$("#id_h_enabled").val("false");
				}
			});

		});
		
		function doSubmit(){
			$('#id_form').form('submit', {
		        url:"<c:url value='/app/manage/sip'/>",
		        onSubmit: function(){
		        	if(isSipNameExist()){
		        		alert(messages.getMsg("account.error.nameExist",[$("#id_account").val()]));
		        		return false;
		        	}else{
						return true;
					}
		        },
		        success:function(data){					
					if("<fmt:message key="operation.success"/>" != data)
						alert(data);
					parent.sipViewObj.reload();
					parent.closeWin();
		        }
			});
		}
		
		// Check whether the same name uesr already existed on the server
		function isSipNameExist(){
			var ret=false;
			var _name=$("#id_account").val();
			var _preName="<c:out value='${sip.account}'/>";
			
			if("${param.opt}"=="modify"&&_name==_preName){//whether the same name in the modify page
				ret=false;
			}else{
				$.ajax({
					url:"<c:url value='/app/manage/sip/check'/>",
					async:false,
					type:"GET",
					data:{
						name:_name,
						times:new Date().toString()
					},
					success:function(data){
						if(data=="true")
							ret=true;
					}
				});
			}
			
			return ret;
		}
		
	</script>
	
	<style type="text/css">
	    html, body {
	        width: 100%;
	        height: 100%;
	        margin: 0px;
	        overflow: hidden;
	    }
	</style>
</head>
<body class="dialog">
	<div id="id_sip" class="table-container">
		<div style="height:20px;"></div>
		<form id="id_form" method="post">
		<c:if test="${param.opt=='modify'}">
			<input type="hidden" value="PUT" name="_method"/>
		</c:if>
		<table>
			<tr>
				<td><fmt:message key='form.sip.account'/></td>
				<td>
				<input id="id_account"
                       <c:if test="${param.opt=='modify'}">readonly="readonly" style="background-color: #DEDBD6;"</c:if>
                       type="text" name="account" required="true" value="${sip.account}" validType="nodelimiter" class="input-text easyui-validatebox"/>
				</td>
			</tr>
             <tr>
				<td><fmt:message key='form.sip.enabled'/></td>
                <td>
					<input type="checkbox" id="id_enabled"/>
					<input type="hidden" value="false" id="id_h_enabled" name="enabled"/>
                    <input type="hidden" value="sip" name="protocol"/>
				</td>
			</tr>
			<tr>
				<td><fmt:message key='form.sip.username'/></td>
				<td><input type="text" name="username" value="${sip.username}" class="input-text easyui-validatebox"/></td>
			</tr>
            <tr>
				<td><fmt:message key='form.sip.authname'/></td>
				<td><input type="text" name="authname" value="${sip.authname}" class="input-text easyui-validatebox"/></td>
			</tr>
			<tr>
				<td><fmt:message key='form.sip.password'/></td>
				<td><input type="password" name="password" value="${sip.password}" class="input-text easyui-validatebox"/></td>
			</tr>
			<tr>
				<td><fmt:message key='form.sip.domain'/></td>
				<td><input type="text" name="domain" value="${sip.domain}" class="input-text easyui-validatebox"/></td>
			</tr>
			<tr>
				<td><fmt:message key='form.sip.registrar'/></td>
				<td><input type="text" name="registrar" value="${sip.registrar}" class="input-text easyui-validatebox"/></td>
			</tr>
			
            <tr>
				<td><fmt:message key='form.sip.description'/></td>
				<td><input type="text" name="description" value="${sip.description}" class="input-text easyui-validatebox"/></td>
			</tr>
			
			<tr>
				<td colspan="2">
					<p align="center">
                        <input type="button" onclick="doSubmit();" class="mybtn" value="<fmt:message key='btn.ok'/>">
						<button onclick="parent.closeWin();" class="mybtn"><fmt:message key='btn.cancel'/></button>
					</p>
				</td>
			</tr>
		</table>
		</form>
		<div style="height:20px;"></div>
	</div>
</body>
</html>